{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">服务订单管理</div>
    <div class="layui-card-body">
        <table class="layui-hide" id="currentTable" lay-filter="currentTable"
               data-auth-add="{:$auth->check('order.pzorder/add')}"
               data-auth-edit="{:$auth->check('order.pzorder/edit')}"
               data-auth-delete="{:$auth->check('order.pzorder/del')}"
        ></table>
    </div>
</div>
<script type="text/html" id="picTpl">
    <img style="max-width:80px; max-height:30px;" src="{{d.avatarUrl}}" data-image="{{d.nickname}}">
</script>

<script type="text/html" id="barTool">

    <a data-open='{:url("sdetail")}?id={{ d.id }}'
       class="layui-btn layui-btn-warm layui-btn-xs {:$auth->check('order.pzorder/sdetail')?'':'layui-hide'}"
       title="查看就诊人信息">服务记录</a>

    <a data-open='{:url("edit")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs {:$auth->check('order.pzorder/edit')?'':'layui-hide'}"
       title="查看就诊人信息">就诊人信息</a>

    {{# if(d.order_type==1){ }}
    <a data-open='{:url("order1")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs {:$auth->check('order.pzorder/order1')?'':'layui-hide'}"
       title="订单信息">医院信息</a>
    {{# } }}
    {{# if(d.order_type==2){ }}
    <a data-open='{:url("order2")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs {:$auth->check('order.pzorder/order2')?'':'layui-hide'}"
       title="订单信息">地址信息</a>
    {{# } }}
<!--    1待支付2带指派3服务中4已完成5已取消6已退款7已指派8已评价-->
    {{# if(d.status==2||d.status==7){ }}
    <a data-open='{:url("pzIndex")}?id={{ d.id }}'
       class="layui-btn layui-btn-xs layui-btn-normal {:$auth->check('order.pzorder/edit')?'':'layui-hide'}"
       title="分配服务人员">分配服务人员</a>
    {{# } }}

    {{# if(d.status==3){ }}
    <a href="javascript:;" onclick="wk.confirm('{{d.id}}','{:url('endOrder')}','确定完成订单吗？')"
       class="layui-btn layui-btn-warm layui-btn-xs {:$auth->check('order.pzorder/endOrder')?'':'layui-hide'}" title="完成订单">完成订单</a>
    {{# } }}

    {{# if(d.status==2||d.status==7){ }}
    <a href="javascript:;" onclick="wk.confirm('{{d.id}}','{:url('refund')}','确定后台退款吗？')"
       class="layui-btn layui-btn-danger layui-btn-xs {:$auth->check('order.pzorder/edit')?'':'layui-hide'}" title="后台退款">后台退款</a>
    {{# } }}
</script>


<!--操作模板-->

{/block}
{block name="script"}
<script>
    var selectElement = null;
    layui.use('yznTable', function () {
        var table = layui.yznTable;

        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: "{:url('add')}",
            edit_url: "{:url('edit')}",
            delete_url: "{:url('del')}",
        };
        var proviec = {:json_encode($proviec)};
        table.render({
            init: init,
            autoWidth: true,
            toolbar: ['refresh',],
            url: '{:url("index")}',
            cols: [
                [
                    //预约时间 是否分派 陪诊服务 陪诊人员 会员折扣 优惠卷金额
                    // {type: 'checkbox', fixed: 'left'},
                    {field: 'id', width: '4%', title: 'ID',search:false},
                    {field: 'order_no', align: "center", width: '18%', title: '订单编号'},
                    {
                        field: 'order_type', align: "center", width: '8%', title: '订单类型', templet: function (d) {
                            if (d.order_type == 1) {
                                return '<span style="color: #0000cc">陪诊订单</span>';
                            } else if (d.order_type == 2) {
                                return '<span style="color: green">护士订单</span>';
                            }else {
                                return '<span>未知</span>';
                            }
                        }, selectList: {1:'陪诊订单',2:'护士订单'}
                    },
                    {field: 'server_name', align: "center", width: '18%', title: '服务项目',search:false},
                    {field: 'nickname', align: "center", width: '10%', title: '下单会员'},
                    {field: 'mobile', align: "center", width: '10%', title: '会员电话'},
                    {field: 'avatarUrl', align: "center", width: '10%', title: '用户头像', templet: '#picTpl',search:false},
                    {field: 'pz_name', align: "center", width: '10%', title: '服务人员',search:false},
                    {field: 'get_money', align: "center", width: '10%', title: '返佣金额',search:false},
                    {
                        //订单状态 1待支付2待指派3服务中4已完成5已取消6已退款7已指派8已评价
                        field: 'status', align: "center", width: '10%', title: '订单状态', templet: function (d) {
                            if (d.status == 1) {
                                return '<span style="color: orangered">待支付</span>';
                            } else if (d.status == 2) {
                                return '<span style="color:  #00B7EE ">待指派</span>';
                            } else if (d.status == 3) {
                                return '<span style="color: #0000FF">服务中</span>';
                            } else if (d.status == 4) {
                                return '<span style="color: #006699">已完成</span>';
                            } else if (d.status == 5) {
                                return '<span style="color: red">已取消</span>';
                            }else if (d.status == 6) {
                                return '<span style="color:green">已退款</span>';
                            }else if (d.status == 7) {
                                return '<span style="color: #c0ccda">已指派</span>';
                            } else if (d.status == 8) {
                                return '<span style="color: #00f7de">已评价</span>';
                            } else {
                                return '<span>未知</span>';
                            }
                        }, selectList: {1:'待支付',2:'待指派',3:'服务中',4:'已完成',5:'已取消',6:'已退款',7:'已指派',8:'已评价'}
                    },
                    {field: 'create_time', align: "center", width: '15%', title: '下单时间', search: 'range'},
                    {field: 'time', align: "center", width: '15%', title: '预约时间', search: 'range'},
                    {field: 'dispatch_time', align: "center", width: '15%', title: '分配时间', search: 'range'},
                    {field: 'start_time', align: "center", width: '15%', title: '服务开始时间', search: 'range'},
                    {field: 'end_time', align: "center", width: '15%', title: '服务结束时间', search: 'range'},
                    {
                        field: 'pay_type', align: "center", width: '10%', title: '支付方式', templet: function (d) {
                            if (d.pay_type == 1) {
                                return '<span style="color: green">直接支付</span>';
                            } else if (d.pay_type == 2) {
                                return '<span style="color: black">陪诊卡支付</span>';
                            }else {
                                return '<span>未知</span>';
                            }
                        }, selectList: {1:'直接支付',2:'陪诊卡支付'}
                    },
                    {
                        field: 'pay_status', align: "center", width: '8%', title: '支付状态', templet: function (d) {
                            if (d.pay_status == 0) {
                                return '<span style="color: red">未支付</span>';
                            } else if (d.pay_status == 1) {
                                return '<span style="color: green">已支付</span>';
                            }else if (d.pay_status == 2) {
                                return '<span style="color: #c0ccda">已退款</span>';
                            } else {
                                return '<span>未知</span>';
                            }
                        }, selectList: {0:'未支付',1:'已支付',2:'已退款'}
                    },
                    {field: 'price', align: "center", width: '10%', title: '订单金额',search:false},
                    {field: 'discount_money', align: "center", width: '10%', title: '会员折扣',search:false},
                    {field: 'pay_money', align: "center", width: '10%', title: '支付金额',search:false},
                    {field: 'pay_time', align: "center", width: '15%', title: '支付时间', search: 'range'},
                    { fixed: 'right',align: 'center',width: '30%', title: '操作',toolbar: '#barTool' }//delete'
                ]
            ],
            page: {}
        });
        yznTable.bindevent();
        selectElement = document.getElementById('c-province');
        selectElement.setAttribute("lay-filter", "c-province");
        form1();
        selectElement2 = document.getElementById('searchFieldset_currentTable');
        selectElement2.classList.remove("layui-hide");
        var element = document.getElementById('layui-input-search');
        element.parentNode.removeChild(element);

    });

    function form1() {
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(c-province)', function (data) {
                console.log(data.value);
                $.ajax({
                    type: "POST",//规定传输方式
                    url: "{:url('getc_cate')}",//提交URL
                    data: {'id': data.value},//提交的数据
                    success: function (result) {
                        if (result.code == 200) {
                            $("#c-city").empty();
                            var str = "<option value>- 全部 -</option>";
                            $.each(result.data, function (i, val) {
                                str += '<option value=' + val.id + '>' + val.name + '</option>'
                            });
                            $("#c-city").append(str);
                            layui.form.render('select');
                        }
                    },
                    error: function () {
                        alert("获取信息失败")
                    }
                });
            })
        });
    }


</script>
{/block}